package cn.lizemin.controller;

import cn.lizemin.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

/**
 * @author lzm
 * @version 1.0
 * @description: 测试使用axios向后端发送请求
 * @date 2022/3/14 11:38
 */
@RestController
@CrossOrigin //用来解决跨域
public class DemoController {

    private static final Logger log = LoggerFactory.getLogger(DemoController.class);

    /**
     * 接收axios的get方式请求，通过？id=xx&name=xx来实现传参
     * @param id
     * @param name
     * @return
     */
    @GetMapping("/demo")
    public String demo(@RequestParam("id") String id, @RequestParam("name") String name){
        log.info("demo ok ....");
        log.info("id:{} name:{}",id,name);
//        int n = 1/0;
        return "demo ok ";
    }

    /**
     * 接收post请求发送过来的JSON格式数据
     * @param user
     * @return
     */
    @PostMapping("/test")
    public String test(@RequestBody User user){
        log.info("test ok ");
        log.info("id:{}  name:{}",user.getId(),user.getName());
        return "test ok ";
    }

    /**
     * 测试axios发送put方式的请求
     * @param user
     * @return
     */
    @PutMapping("/test1")
    public String test1(@RequestBody User user){
        log.info("test1 ok ");
        log.info("id:{}  name:{}",user.getId(),user.getName());
        return "test1 ok ";
    }


}

